app.controller('yinhuanluruCtrl',['$scope','serv','$location','$http','mainService',function($scope,serv,$location,$http,mainService){
    $scope.item = serv.getData();
    console.log($scope.item);
    console.log(mainService.getData().fzrData);
    if(JSON.parse(localStorage.getItem('userData')).controlFlag == "1") {
        $scope.show = true;
    }
    if(mainService.getData()){
            $scope.yhcs = mainService.getData().yhcs;
            $scope.jtwz = mainService.getData().jtwz;
            $scope.yhms = mainService.getData().yhms;
            $scope.fzr = mainService.getData().fzr;
            $scope.yjya = mainService.getData().yjya;
            $scope.zgyq = mainService.getData().zgyq;
            $scope.kzcs = mainService.getData().kzcs;
            $scope.cuoshi = mainService.getData().cuoshi;

    }

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position){
            var coords = position.coords;
            var latlng = new google.maps.LatLng(
                // 维度
                $scope.xLo = coords.latitude,
                // 精度
                $scope.yLo = coords.longitude
            );    }, function (error) {$scope.xLo = '';$scope.yLo=''; console.log(error) },{
            // 指示浏览器获取高精度的位置，默认为false
            enableHighAcuracy: true,
            // 指定获取地理位置的超时时间，默认不限时，单位为毫秒
            timeout: 5000,
            // 最长有效期，在重复获取地理位置时，此参数指定多久再次获取位置。
            maximumAge: 3000
        });

    }else{
        alert("Your browser does not support Geolocation!");
    }
    //console.log($scope.xLo+$scope.yLo);

    $scope.changeState = function () {

        mainService.setData({
            yhcs:$scope.yhcs,
            jtwz:$scope.jtwz,
            yhms:$scope.yhms,
            fzr:$scope.fzr,
            yjya:$scope.yjya,
            zgyq:$scope.zgyq,
            kzcs:$scope.kzcs,
            cuoshi:$scope.cuoshi,
            fzrData:mainService.getData().fzrData,
            yhcsData:mainService.getData().yhcsData,
            yjyaData:mainService.getData().yjyaData,
            page:'luru'
        })
        console.log(mainService.getData())
    };

    $scope.submit = function () {
        var token = localStorage.getItem('token');
        // var guanliquanxian = localStorage.getItem('controlFlag');
        if(getInputs()==false){
            return;
        }





        mui.showLoading('加载中', 'div');
        if (JSON.parse(localStorage.getItem('userData')).controlFlag == "1") {
            $http({
                method: "POST",
                url: mainUrl + '/tr/tr-chek-item!addTrCheckPlanSave.action',
                params: {

                    'Authorization': token,
                    // 'qm.jsonStr':[{"sid": ,"trFlag": ,'remark':'','gpsLocation': ,'version': }]
                    /*'qm.flag' : 1*/
                },
                body:{

                    'qm.orgSid': mainService.getData().yhcsData.sid,
                    'qm.psid': Number($scope.item.sid),
                    'qm.riskLevel': $scope.item.riskLevel,
                    'qm.troDesc': $scope.yhms,
                    'qm.troLevel': $scope.item.troLevel,
                    'qm.troMethod': $scope.cuoshi,
                    'qm.troPlace': $scope.yhcs,
                    'qm.troPosition': $scope.jtwz,
                    'qm.gpsLocation': $scope.xLo+$scope.yLo,
                    'qm.delegateBy':mainService.getData().fzrData.sid,
                    'qm.delegateOrp':mainService.getData().fzrData.orpSid,
                    'qm.delegateName': $scope.fzr,
                    'qm.emeDeal':$scope.yjya,
                    'qm.planDt': localStorage.getItem('dateInput'),
                    'qm.troRequire': $scope.zgyq,
                    'qm.troSourceUrl':'',
                        // mainService.getUrl().name,
                    'troSourceUrl': ''
                        // mainService.getFile()
                }
            }).then(
                function (data, status, headers, config) {
                    console.log(data)
                    //$scope.data = data.data.items;

                    mui.hideLoading();
                    mui.toast('提交成功');
                    $location.path('/renwuxiangqing');
                    mainService.reset()
                    // document.getElementsByClassName('mui-switch-blue').addEventListener
                }, function (data, status, headers, config) {
                    console.log(data)
                    console.log(status)
                })


            // localStorage.removeItem('yhcs');
            // localStorage.removeItem('fzr');
            // localStorage.removeItem('jtwz');
            // localStorage.removeItem('yjya');
            // localStorage.removeItem('zgyq');
            // localStorage.removeItem('dateInput');
            // localStorage.removeItem('yhms');
        }else{
            $http({
                method: "POST",
                url: mainUrl + '/tr/tr-chek-item!addTrCheckPlanSave.action',
                params: {
                    'Authorization': token,
                    'qm.orgSid': mainService.getData().yhcsData.sid,
                    'qm.psid': Number($scope.item.sid),
                    'qm.riskLevel': $scope.item.riskLevel,
                    'qm.troDesc': $scope.yhms,
                    'qm.troLevel': $scope.item.troLevel,
                    'qm.troMethod':  $scope.cuoshi,
                    'qm.troPlace': $scope.yhcs,
                    'qm.troPosition': $scope.jtwz,
                    'qm.gpsLocation':  $scope.xLo+$scope.yLo,
                    'qm.delegateBy':  mainService.getData().fzrData.sid,
                    'qm.delegateName': $scope.fzr,
                    'qm.emeDeal':$scope.yjya,
                    'qm.planDt': localStorage.getItem('dateInput'),
                    'qm.troRequire': $scope.zgyq,
                    'qm.troSourceUrl': '',
                    'troSourceUrl': ''
                    // 'qm.jsonStr':[{"sid": ,"trFlag": ,'remark':'','gpsLocation': ,'version': }]
                    /*'qm.flag' : 1*/

                }
            }).then(
                function (data, status, headers, config) {
                    console.log(data);
                    //$scope.data = data.data.items;

                    mui.hideLoading();
                    mui.toast('提交成功');
                    $location.path('/renwuxiangqing');
                    // document.getElementsByClassName('mui-switch-blue').addEventListener
                }, function (data, status, headers, config) {
                    console.log(data);
                    console.log(status)
                });



        }

    }
}]);

